package com.xtkj.superclub_friendscircle.task;

import com.xtkj.superclub_friendscircle.service.ILike2DBService;
import lombok.extern.slf4j.Slf4j;
import org.quartz.JobExecutionContext;
import org.quartz.JobExecutionException;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.scheduling.quartz.QuartzJobBean;

import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 项目名称：superclub
 * 类 名 称：LikeTask
 * 类 描 述：TODO
 * 创建时间：2020/1/4 9:49
 * 创 建 人：xiezhiyan
 */
@Slf4j
public class LikeTask extends QuartzJobBean {

    @Autowired
    ILike2DBService likedService;

    private SimpleDateFormat sdf = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");

    @Scheduled(cron = "0 0/30 * * * *")//每天凌晨执行
    @Override
    protected void executeInternal(JobExecutionContext jobExecutionContext) throws JobExecutionException {

        log.info("LikeTask-------- {}", sdf.format(new Date()));

        //将 Redis 里的点赞信息同步到数据库里
        likedService.transLikedFromRedis2DB();

        likedService.transLikedCountFromRedis2DB();
    }
}